//app.js
App({
    onLaunch: function () {
        // 展示本地存储能力
        var logs = wx.getStorageSync('logs') || [];
        logs.unshift(Date.now());
        wx.setStorageSync('logs', logs);
        //调用微信登录接口
    },
    handlerPost: function (url, data, type) {
        var promise = new Promise((resolve, reject) => {
            wx.request({
              url: 'https://api.hqctv.com.cn/' + url,
                data: data,
                method: type,
                header: {'content-type': 'application/x-www-form-urlencoded'},
                success: function (res) {
                    resolve(res);
                },
                error: function (e) {
                    reject(e);
                    console.log("请求失败")
                }
            })
        });
        return promise;
    },
    login: function (param) {
        wx.request({
          url: 'https://api.hqctv.com.cn/api/account/doGetOpenId.do',
            data: param,
            header: {
                'content-type': "application/json",
            },
            success: function (res) {
                if (res) {
                    if (res.data.msg == 'SUCCESS') {
                        wx.setStorageSync('sessionid',res.data.data.openid);
                    }
                }

            }
        })
    },
    globalData: {
        commonUrl: 'https://hqctv.oss-cn-beijing.aliyuncs.com/',
        userInfo: null,
        openid: wx.getStorageSync('sessionid'),
    },
    fetchAddressList() {
        setTimeout(res => {
            wx.hideLoading();
        }, 500);

    },
    onLoad: function () {
    },
    getCommonTime: function () {
        Date.prototype.Format = function (fmt) { // author: meizz
            var o = {
                "M+": this.getMonth() + 1, // 月份
                "d+": this.getDate(), // 日
                "h+": this.getHours(), // 小时
                "m+": this.getMinutes(), // 分
                "s+": this.getSeconds(), // 秒
                "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
                "S": this.getMilliseconds() // 毫秒
            };
            if (/(y+)/.test(fmt))
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }
    },
    getTrim: function () {
        String.prototype.trim = function () {
            return this.replace(/^\s+|\s+$/g, '');
        }
    },
});